Formius.Validator_Abstract = $.inherit({
	_ns: '',
	
	/**
	* @var String
	*/
	_code: null,
	
	/**
	* @var Object
	*/
	_messages: {
		INVALID: 'Неверное значение',
		UNKNOWN_COMPARE: 'Не передано значение для сравнения'
	},
	
	/**
	* @var Object
	*/
	_options: {},
	
	__constructor: function(options) {
		this.setOptions(options || {});
	},
	
	/**
	 * @param String ns
	 * @return Void
	 */
	setNS: function(ns) {
		this._ns = ns;
	},

	/**
	 * @return String
	 */
	getNS: function() {
		return this._ns;
	},

	/**
	* @return String
	*/
	getCode: function() {
		return this._code;
	},

	/**
	* @return String
	*/
	getMessage: function() {
		if (this._code == null) {
			return null;
		}
		if (typeof(this._messages[this.getCode()] != 'undefined')) {
			var message = this._messages[this.getCode()];
			for (var i in this._options) {
				message = Formius.Helper.replace('{' + i + '}', this._options[i], message);
			}
			return message;
		}
		return this.getCode();
	},
	
	/**
	* @param Mixed value
	* @return Boolean
	*/
	isValid: function(value) {
		if ('__value' in this._options) {
			value = this._options.__value;
		}
		if ('value' in this._options) {
			if (typeof(value) != 'undefined') {
				this.setOptions({value: value});
			} else {
				value = this._options['value'];
			}
		} else {
			this.setOptions({value: value});
		}
		var valid = false;
		if ((valid = this._isValid(value))) {
			this._setCode(null);
		}
		return valid;
	},

	/**
	* @param Object messages
	* @return Void
	*/
	setMessages: function(messages) {
		this._messages = $.extend(this._messages, messages);
	},

	/**
	* @param Object options
	*/
	setOptions: function(options) {
		this._options = $.extend(this._options, options || {});
	},
	
	/**
	 * @return Void
	 */
	reset: function() {
		this._setCode(null);
	},

	/**
	* @param String code
	*/
	_setCode: function(code) {
		this._code = code;
	}
});